import 'package:flutter/material.dart';
import 'package:flutter_jd/pages/message/controller.dart';
import 'package:flutter_jd/ui/widgets/body/top_bar.dart';
import 'package:flutter_jd/ui/widgets/kit.dart';
import 'package:flutter_jd/ui/widgets/refresh/pull_refresh.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// 消息
class Message extends GetView<MessageController> {
  @override
  Widget build(BuildContext context) {
    Get.put(MessageController());

    return Scaffold(
      backgroundColor: Color(0xFFF5F5F5),
      appBar: TopBar(
        title: '消息',
        isBack: true,
      ),
      body: PullRefresh(
        refreshController: controller.refreshController,
        onRefresh: controller.onRefresh,
        onLoading: controller.onLoading,
        child: ListView.builder(
          itemCount: controller.messageList.length,
          itemBuilder: (BuildContext context, int index) {
            Map item = controller.messageList[index];

            return _buildList(item, index);
          },
        ),
      ),
    );
  }

  Widget _buildList(Map item, int index) {
    return Container(
      margin: EdgeInsets.only(top: index == 0 ? 8.h : 0.h),
      child: Ink(
        decoration: BoxDecoration(
          color: Colors.white,
        ),
        child: InkWell(
          onTap: () {},
          child: Container(
            padding: EdgeInsets.symmetric(
              horizontal: 12.w,
            ),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: 50.r,
                  height: 50.r,
                  decoration: BoxDecoration(
                    color: item['color'],
                    border: Border.all(
                      color: Colors.white,
                      width: 1.5.r,
                    ),
                    borderRadius: BorderRadius.circular(50.r),
                  ),
                  child: Kit.iconFont(0xe70a, Colors.white, 22.sp),
                ),
                Expanded(
                  child: Container(
                    padding: EdgeInsets.only(
                      left: 12.w,
                      top: 12.h,
                      bottom: 12.h,
                    ),
                    decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(
                          color: Color(0xFFF5F5F5),
                          width: 1,
                        ),
                      ),
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              item['user'],
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                color: Color(0xFF333333),
                                fontSize: 14.sp,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                            Container(
                              margin: EdgeInsets.only(right: 7.w),
                              child: Text(
                                item['date'],
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: Color(0xFF999999),
                                  fontSize: 11.sp,
                                  fontWeight: FontWeight.w500,
                                ),
                              ),
                            )
                          ],
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 1.w, top: 5.h),
                          child: Text(
                            item['message'],
                            maxLines: 2,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                              color: Color(0xFF888888),
                              fontSize: 13.5.sp,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
